﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ReadWaterlevelData
{
    public class SettingsManager
    {
        public const string SectionName = "mySettings";
        public static void SaveSettings(WaterlevelSettings settings)
        {
            if (settings == null)
            {
                settings = new WaterlevelSettings();
            }

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.Sections.Remove("mySettings");
            //ConfigurationManager.RefreshSection("mySettings");
            //ConfigurationSection section = config.Sections["mySettings"];
            //section  == null && !section.ElementInformation.IsLocked
            if (config.Sections["mySettings"] == null)
            {
                config.Sections.Add("mySettings", settings);
            }
            else
            {
                
            }
            config.Save();
            ConfigurationManager.RefreshSection("mySettings");
        }

        public static WaterlevelSettings GetSettings()
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            return config.GetSection("mySettings") as WaterlevelSettings;
        }
    }
}
